
threshold=1.2;

cell_cnt=0;
avg_act_WT=[];
cnt=0;
xcorr_roi_WT=[];
for reg_ind=1:size(AV_data_WT,2)
    
    [nbr_samples nbr_cells]=size(AV_data_WT(reg_ind).raw_act);
    curr_reg_act=zeros(nbr_samples,nbr_cells);
    for ind=1:nbr_cells
        cell_cnt=cell_cnt+1;
        avg_act_WT(cell_cnt)=sum(AV_data_WT(reg_ind).raw_act(:,ind)>threshold)/nbr_samples;
        curr_reg_act(:,ind)=AV_data_WT(reg_ind).raw_act(:,ind)>threshold;
    end
    
    %figure;imagesc(curr_reg_act')
    for ind=1:nbr_cells
        for knd=ind+1:nbr_cells
            cnt=cnt+1;
            a=curr_reg_act(:,ind);
            b=curr_reg_act(:,knd);
            xcorr_roi_WT(cnt)=(a-mean(a))'*(b-mean(b))/std(a)/std(b);
        end
    end
   
end



cell_cnt=0;
avg_act_APP=[];
cnt=0;
xcorr_roi_APP=[];
for reg_ind=1:size(AV_data_APP,2)
    
    [nbr_samples nbr_cells]=size(AV_data_APP(reg_ind).raw_act);
    curr_reg_act=zeros(nbr_samples,nbr_cells);
    for ind=1:nbr_cells
        cell_cnt=cell_cnt+1;
        avg_act_APP(cell_cnt)=sum(AV_data_APP(reg_ind).raw_act(:,ind)>threshold)/nbr_samples;
        curr_reg_act(:,ind)=AV_data_APP(reg_ind).raw_act(:,ind)>threshold;
    end
    
    %figure;imagesc(curr_reg_act')
    for ind=1:nbr_cells
        for knd=ind+1:nbr_cells
            cnt=cnt+1;
            a=curr_reg_act(:,ind);
            b=curr_reg_act(:,knd);
            xcorr_roi_APP(cnt)=(a-mean(a))'*(b-mean(b))/std(a)/std(b);
        end
    end
end


figure;
hist(avg_act_WT,100)


figure;
hist(avg_act_APP,100)


[hist_WT,bins]=hist(xcorr_roi_WT,100);
[hist_APP]=hist(xcorr_roi_APP,bins);


figure;
plot(bins,hist_WT/sum(~isnan(xcorr_roi_WT)))
hold on
plot(bins,hist_APP/sum(~isnan(xcorr_roi_APP)),'r')


figure;
plot(bins,hist_WT)
hold on
plot(bins,hist_APP,'r')




